package com.maimang.platform.common.service.impl;

import java.util.Date;
import java.util.List;

import com.maimang.platform.common.entity.SysApiLog;
import com.maimang.platform.common.mapper.SysApiLogMapper;
import com.maimang.platform.common.service.SysApiLogService;
import com.maimang.platform.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.maimang.platform.lang.ConvertUtils;
import tk.mybatis.mapper.entity.Example;

/**
 * @classname SysApiLogServiceImpl
 * @description <br>远程API接口请求日志记录服务层实现类</br>
 * @author  Rocky
 * @date    2019-09-04 16:37:40
 * @email   jintaozhao@qq.com
 * @version 1.0.0
 */
@Service
public class SysApiLogServiceImpl implements SysApiLogService {

	@Autowired
	private SysApiLogMapper sysApiLogMapper;

	/**
     * 查询远程API接口请求日志记录信息
     * 
     * @param logId 远程API接口请求日志记录ID
     * @return 远程API接口请求日志记录信息
     */
    @Override
	public SysApiLog selectSysApiLogById(Integer logId) {
	    return sysApiLogMapper.selectSysApiLogById(logId);
	}
	
	/**
     * 查询远程API接口请求日志记录列表
     * 
     * @param sysApiLog 远程API接口请求日志记录信息
     * @return 远程API接口请求日志记录集合
     */
	@Override
	public List<SysApiLog> selectSysApiLogList(SysApiLog sysApiLog) {
	    return sysApiLogMapper.selectSysApiLogList(sysApiLog);
	}
	
    /**
     * 新增远程API接口请求日志记录
     * 
     * @param sysApiLog 远程API接口请求日志记录信息
     * @return 结果
     */
	@Override
	public int insertSysApiLog(SysApiLog sysApiLog) {
	    return sysApiLogMapper.insertSysApiLog(sysApiLog);
	}
	
	/**
     * 修改远程API接口请求日志记录
     * 
     * @param sysApiLog 远程API接口请求日志记录信息
     * @return 结果
     */
	@Override
	public int updateSysApiLog(SysApiLog sysApiLog) {
	    return sysApiLogMapper.updateSysApiLog(sysApiLog);
	}

	/**
     * 删除远程API接口请求日志记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteSysApiLogByIds(String ids) {
		return sysApiLogMapper.deleteSysApiLogByIds(ConvertUtils.toStrArray(ids));
	}

	/**
	 * 删除days天之前的日志
	 *
	 * @param days 天数，表示多少天前的日志
	 * @return
	 */
	@Override
	public int deleteHistoryLogs(int days) {
		Date thatDate = DateUtils.addDays(new Date(), -days);
		Example example = new Example(SysApiLog.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andLessThanOrEqualTo("operTime", thatDate);
		return sysApiLogMapper.deleteByExample(example);
	}

	@Override
	public void cleanApiLog() {
		sysApiLogMapper.cleanApiLog();
	}

}
